package importPool;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;


import java.util.Stack;
import java.util.Vector;

import javax.swing.JButton;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

import javax.swing.JPanel;



import dbmanager.DBManager;
import dbmanager.GetIdName;



public class Register  extends JFrame implements ActionListener,ItemListener
{
	private static final long serialVersionUID = 1L;
	
	private JLabel lable11;

	private Vector<Object>jCombo = new Vector<Object>();
	private Stack< Object>importStack=new Stack<Object>();
 	private JButton Register;
 	private JPanel contentPane;
 	
	private String inputpath;

	private String fields;
	DBManager sqlDB=new DBManager();
	GetIdName gin=new GetIdName(sqlDB);
	private String tablename=" ";
  
	public Register() 
 	{ 
 		super(); 
 		getPath();
 		getfields();
 		
 		initializeComponent();
 		this.setVisible(true); 
 	} 
 	private void initializeComponent() 
 	{ 
 		
 		//Inheritence = new JButton();
 		//Sort = new JButton();
 		Register = new JButton();
 		
 		lable11 = new JLabel("Table_name");
 		JComboBox option1 =new JComboBox();
 		
 		
 ///Problem Of HardCoding----> Because it is very much specific to Master and Rate_master Only
 ///Should Have Other Solution
 		option1.addItem("Master_table");
 		option1.addItem("Rate_master");
 
 		contentPane = (JPanel)this.getContentPane();
 		Register.setText("Register");
 		contentPane.setLayout(null);
 		
 		
 		addComponent(contentPane, lable11, 40,15,80,30);
 		addComponent(contentPane, option1, 120,15,170,30);
 		addComponent(contentPane,Register, 120,80,170,30);
 		
 	
 		Register.addActionListener(this);
 		jCombo.add(option1);
 		
 		this.setTitle("Register"); 
 		this.setLocation(new Point(0, 0)); 
 		this.setSize(new Dimension(457, 220)); 
 	} 
  
 	
 	private void addComponent(Container container,Component c,int x,int y,int width,int height) 
 	{ 
 		c.setBounds(x,y,width,height); 
 		container.add(c); 
 	} 
 	
	public void actionPerformed(ActionEvent ae)
	{	
		if(ae.getSource()==Register)
		{
			JComboBox jc;
			try
			{
				
				for(int	i=0;i<jCombo.size();i++)
				{
					jc=(JComboBox) jCombo.get(i);
					if(jc.isEnabled()==true)
					{
						tablename=jc.getSelectedItem().toString();						
						//JOptionPane.showMessageDialog(this,tablename);
					}
				}
				String str[]=fields.split("\t");
				importStack.push(this);
				@SuppressWarnings("unused")
				SelectFields sf=new SelectFields(str,inputpath,tablename,importStack);
				setVisible(false);
			}
			catch(Exception e)
			{
			}
		}
	}
 	public static void main(String[] args) 
 	{ 
 		new Register(); 
 	}
	public void itemStateChanged(ItemEvent i) 
	{
	
		try
		{				
				JComboBox cb=(JComboBox)i.getItem();
				@SuppressWarnings("unused")
				String tablename=" ";
				tablename=cb.getInputContext().toString();				
		}
		catch(Exception e){			
		}

	}

	
	public void setPath(String path)
	{
		this.inputpath=path;		
	
	}
	public void setFields(String fields)
	{
		this.fields=fields;
		
	}
	public String getPath()
	{
		return inputpath;		
	
	}
	public String getfields()
	{
		return fields;
	}
	
	public void setImportStack(Stack<Object> importStack)
	{
		this.importStack=importStack;
	}
	public Stack<Object> getImportStack()
	{
		return importStack;		
	}

}
